package action;

import entity.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 石小俊
 * @date 2023年11月01日 16:55
 */
public class UserAction {

    public String login(HttpServletRequest request, HttpServletResponse response){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if("admin".equals(username) && "123456".equals(password)){
            User user = new User(1,"admin","123456","13812345678","江苏-南京");
            request.getSession().setAttribute("user",user);
            return "success";
        }
        request.setAttribute("loginMsg","用户名或密码错误");
        return "fail";
    }

    public String register(HttpServletRequest request, HttpServletResponse response){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String phone = request.getParameter("phone");
        String address = request.getParameter("address");
        if("admin".equals(username)){
            request.setAttribute("registerMsg","该用户已经被注册");
            return "fail";
        }
        return "success";
    }

    public String logout(HttpServletRequest request,HttpServletResponse response){
        request.getSession().invalidate();
        return "success";
    }

}
